#pragma once

#include <stdlib.h>
#include <time.h>
#include "GameObject.h"
#include "Node.h"
#include "AStar.h"
#include "InputHandler.h"
#include "SFML\Audio.hpp"
class BehaviorNode;

enum Animals
{
	Bunny,
	Wolf,
	Bear
};

class Agent : public GameObject
{
	public:
		Agent();
		~Agent();


		struct NodeSenseData
		{
			Node* m_Node;
			int m_ManhattanDistance;
		};

		struct CombinedData
		{
		vector<NodeSenseData*> m_SearchDataList;
		Node* ClosestThreat;
		Node* ClosestFood;
		};

		CombinedData m_CData;
		

		virtual void Initialize(std::vector<std::vector<Node*>> &pGrid);
		virtual void Cleanup();
		virtual void Update(float pDeltaTime);

		void SetCurrentNode(Node* pNode);
		bool HasReached(){ return m_bReachedTarget; }
		bool ShouldKill(){ return m_bKill; }
		void ShouldBeDeleted(){ m_bKill = true; }

		Animals GetAnimalType(){ return m_xAnimalType; };
		void Wander();

		/** VIRTUAL - Search immediate area for things do to */
		void SearchArea2();

		/** VIRTUAL - Look at possible things to do and do the best one */
		virtual void Think() = 0;

		/** VIRTUAL - Interact with object or agents */
		virtual void Act() = 0;

		/** Find path to current objective if needed */
		bool FindPath(Node* pNode);

		/** Used for traveling the path generated by FindPath() */
		void Travel();

		double PointDistance(sf::Vector2f pPointA, sf::Vector2f pPointB);

	protected:
		/** Class used for the pathfinding for the agent */
		AStar aStar;

		/**  Class used for decision making */
		BehaviorNode* m_xBehaviorTree;

		/** Grid reference from the game class */
		std::vector<std::vector<Node*>> Grid;

		// Animal Type
		Animals m_xAnimalType;

		/** Variables used for target and current nodes and movement */
		Node* m_xCurrentNode;
		
		Node* m_xTargetNode;
		sf::Vector2f m_vTargetPosition;
		float m_fCheckRange;

		bool m_bReachedTarget;
		bool m_bFinishedPath;
		std::vector<Node*> m_vPath;
		int m_iPathID;

		/** 
		* Sense range, range of the area the agent can search through. 
		* Grid around the agent m_iSenseRange x m_iSenseRange
		*/
		int m_iSenseRange;

		/** Hunger */
		float m_fHunger;
		bool m_bKill;

		/** Misc util variables */
		float m_fKeyboardDelay;
		float m_fIdleTimer;

		float m_fMoveSpeed;
		// Player click to kill
		sf::Vector2f m_vSize;


		sf::SoundBuffer m_xBuffer;
		sf::Sound m_xSound;
};

